home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "ParseDemo.h"
- #include "SpeedTest.h"
- #include "PlotTest.h"
- //---------------------------------------------------------------------------
- #pragma resource "*.dfm"
- TFParser *FParser;
- //---------------------------------------------------------------------------
- __fastcall TFParser::TFParser(TComponent* Owner)
- : TForm(Owner)
- {
- hParser = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::FormCreate(TObject *Sender)
- {
- //Loading of the csbparse.DLL
- if (InitSTDsbParserDLL() == true) {
-
- //Create an sbParser object and receive its HANDLE
- hParser = CreateNewParser("0", 6, "xyzuvw");
- if (GetIsError(hParser)) {
-
- char errText[50];
-
- //An error has occurred (see documentation)
- MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Function (see documentation)",
- MB_ICONERROR);
- Application->Terminate();
- }
- }
- else { //Loading csbparse.DLL failed
- Application->Terminate();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::FormShow(TObject *Sender)
- {
- char tempstr[50];
-
- Caption = "Demo for Borland C++ Builder ";
- // Caption = Caption + GetParserVersionNumber(tempstr);
- MFunction->Text = "0";
- }
-
- void TFParser::GetBaseAndAngUnit(TForm* pForm,
- int* BaseIn, int* BaseOut, int* AngularUnit)
- {
- //Get the base for the input
- if (RBDEC->Checked)
- *BaseIn = 10;
- if (RBBIN->Checked)
- *BaseIn = 2;
- if (RBHEX->Checked)
- *BaseIn = 16;
- if (RBOCT->Checked)
- *BaseIn = 8;
-
- //Get the base for the output
- if (RBDECOut->Checked)
- *BaseOut = 10;
- if (RBBINOut->Checked)
- *BaseOut = 2;
- if (RBHEXOut->Checked)
- *BaseOut = 16;
- if (RBOCTOut->Checked)
- *BaseOut = 8;
-
- //Get the angular unit
- if (RBDEG->Checked)
- *AngularUnit = 1;
- if (RBRAD->Checked)
- *AngularUnit = 2;
- if (RBGRA->Checked)
- *AngularUnit = 3;
- }
-
- bool TFParser::GetVarValues(TForm* pForm, int BaseIn, long double varValues[])
- {
- bool err = false;
- int errPos = -1;
-
- //Convert the strings of the variables to long double
- varValues[0]=ConvertBaseTold(ExValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable x causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
- varValues[1]=ConvertBaseTold(EyValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable y causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
- varValues[2]=ConvertBaseTold(EzValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable z causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
- varValues[3]=ConvertBaseTold(EuValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable u causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
- varValues[4]=ConvertBaseTold(EvValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable v causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
- varValues[5]=ConvertBaseTold(EwValue->Text.c_str(), BaseIn, &errPos);
- if (errPos >= 0) {
- MessageBox(pForm->Handle, "The string of the variable w causes an error.", "Error",
- MB_ICONERROR);
- err=true;
- }
-
- return err;
- }
-
- bool TFParser::Calculate(TForm* pForm, char* Function, long double varValues[],
- int BaseIn, int BaseOut, int AngularUnit, long double* Result)
- {
- bool err = false;
-
- if (strlen(Function) > 0)
- {
- char errText[50];
-
- SetBaseTo(hParser, BaseIn);
-
- if (GetIsOriginFunc(hParser, Function) == false) {
- Screen->Cursor = crHourGlass;
- SetNewFunction(hParser, Function);
- Screen->Cursor = crDefault;
-
- if (GetIsError(hParser)) {
- //An error has occurred (see documentation)
- MessageBox(pForm->Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Function (see documentation)",
- MB_ICONERROR);
-
- *Result = 0;
- err = true;
- }
- }
-
- if (err == false) {
- SetAngularUnitTo(hParser, AngularUnit);
-
- //Compute the result
- *Result = GetResultExt(hParser, varValues);
-
- if (GetIsError(hParser)) {
- //An error has occurred (see documentation)
- MessageBox(pForm->Handle, ldtochar(errText, GetGlobalError(hParser)),
- "Errornumber in Calculation (see documentation)", MB_ICONERROR);
-
- *Result = 0;
- err = true;
- }
- else {
- err = false;
- }
- }
- }
- else
- {
- if (pForm != FPlotTest)
- MessageBox(pForm->Handle, "There is no function to compute.", "Error",
- MB_ICONERROR);
- }
-
- return err;
- }
-
- //---------------------------------------------------------------------------
- void __fastcall TFParser::BResultClick(TObject *Sender)
- {
- long ctime = GetCurrentTime();
-
- int BaseIn;
- int BaseOut;
- int AngularUnit;
-
- GetBaseAndAngUnit(this, &BaseIn, &BaseOut, &AngularUnit);
-
- long double varValues[6];
- bool err = false;
-
- err = GetVarValues(this, BaseIn, varValues);
-
- if (err==false)
- {
- long double Result;
- char tempstr[50];
-
- Screen->Cursor = crHourGlass;
- err = Calculate(this, MFunction->Text.c_str(), varValues,
- BaseIn, BaseOut, AngularUnit, &Result);
- Screen->Cursor = crDefault;
-
- //Convert the long double to a string
- ConvertToBase(tempstr,Result,15,BaseOut);
-
- EResult->Text = tempstr;
- }
-
- if (err) {
- EResult->Text = "Error";
- ctime = 0;
- }
- else {
- ctime = GetCurrentTime() - ctime;
- }
-
- char tempstr[50];
-
- LtheTime->Caption = ldtochar(tempstr, (long double)ctime/1000, 6);
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::MFunctionChange(TObject *Sender)
- {
- EResult->Text = "no result ...";
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::BExitClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::FormDestroy(TObject *Sender)
- {
- //Delete of the sbParser object
- DeleteParser(hParser);
-
- //Unloading of the csbparse.DLL
- DeinitSTDsbParserDLL();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::BSaveClick(TObject *Sender)
- {
- TFileName NameOfFile;
- AnsiString BaseIn;
- AnsiString BaseOut;
- AnsiString AngularUnit;
- char tempstr[50];
-
- if(DSave->Execute()) {
- MFunctionChange(Sender);
- Caption = "Demo for Borland C++ Builder ";
- // Caption = Caption + GetParserVersionNumber(tempstr);
- Caption = Caption + " - ";
- Caption = Caption + DSave->FileName;
-
- NameOfFile = DSave->FileName;
- if (NameOfFile.Length() > 3) {
- if (NameOfFile[NameOfFile.Length()-3] != '.')
- NameOfFile = NameOfFile + ".sbc";
- }
- else {
- NameOfFile = NameOfFile + ".sbc";
- }
- WritePrivateProfileString("Data", "f(x,y,z,u,v,w)",
- MFunction->Text.c_str(), NameOfFile.c_str());
-
- WritePrivateProfileString("Data", "xVariable",
- ExValue->Text.c_str(), NameOfFile.c_str());
- WritePrivateProfileString("Data", "yVariable",
- EyValue->Text.c_str(), NameOfFile.c_str());
- WritePrivateProfileString("Data", "zVariable",
- EzValue->Text.c_str(), NameOfFile.c_str());
- WritePrivateProfileString("Data", "uVariable",
- EuValue->Text.c_str(), NameOfFile.c_str());
- WritePrivateProfileString("Data", "vVariable",
- EvValue->Text.c_str(), NameOfFile.c_str());
- WritePrivateProfileString("Data", "wVariable",
- EwValue->Text.c_str(), NameOfFile.c_str());
-
- if (RBDEC->Checked)
- BaseIn = "10";
- if (RBBIN->Checked)
- BaseIn = "2";
- if (RBHEX->Checked)
- BaseIn = "16";
- if (RBOCT->Checked)
- BaseIn = "8";
- WritePrivateProfileString("Data", "BaseIn",
- BaseIn.c_str(), NameOfFile.c_str());
-
- if (RBDECOut->Checked)
- BaseOut = "10";
- if (RBBINOut->Checked)
- BaseOut = "2";
- if (RBHEXOut->Checked)
- BaseOut = "16";
- if (RBOCTOut->Checked)
- BaseOut = "8";
- WritePrivateProfileString("Data", "BaseOut",
- BaseOut.c_str(), NameOfFile.c_str());
-
- if (RBDEG->Checked)
- AngularUnit = "1";
- if (RBRAD->Checked)
- AngularUnit = "2";
- if (RBGRA->Checked)
- AngularUnit = "3";
- WritePrivateProfileString("Data", "AngularUnit",
- AngularUnit.c_str(), NameOfFile.c_str());
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::BOpenClick(TObject *Sender)
- {
- TFileName NameOfFile;
- char* tempStr = new char[65000];
- AnsiString BaseIn;
- AnsiString BaseOut;
- AnsiString AngularUnit;
- char tempstr[50];
-
- if(DOpen->Execute()) {
- MFunctionChange(Sender);
- Caption = "Demo for Borland C++ Builder ";
- // Caption = Caption + GetParserVersionNumber(tempstr);
- Caption = Caption + " - ";
- Caption = Caption + DOpen->FileName;
-
- NameOfFile = DOpen->FileName;
- GetPrivateProfileString("Data", "f(x,y,z,u,v,w)", "", tempStr,
- 64999, NameOfFile.c_str());
- MFunction->Text = tempStr;
-
- GetPrivateProfileString("Data", "xVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- ExValue->Text = tempStr;
- GetPrivateProfileString("Data", "yVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- EyValue->Text = tempStr;
- GetPrivateProfileString("Data", "zVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- EzValue->Text = tempStr;
- GetPrivateProfileString("Data", "uVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- EuValue->Text = tempStr;
- GetPrivateProfileString("Data", "vVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- EvValue->Text = tempStr;
- GetPrivateProfileString("Data", "wVariable", "0", tempStr,
- 64999, NameOfFile.c_str());
- EwValue->Text = tempStr;
-
- GetPrivateProfileString("Data", "BaseIn", "10", tempStr,
- 64999, NameOfFile.c_str());
- BaseIn = tempStr;
- if (BaseIn == "10")
- RBDEC->Checked = true;
- if (BaseIn == "2")
- RBBIN->Checked = true;
- if (BaseIn == "16")
- RBHEX->Checked = true;
- if (BaseIn == "8")
- RBOCT->Checked = true;
-
- GetPrivateProfileString("Data", "BaseOut", "10", tempStr,
- 64999, NameOfFile.c_str());
- BaseOut = tempStr;
- if (BaseOut == "10")
- RBDECOut->Checked = true;
- if (BaseOut == "2")
- RBBINOut->Checked = true;
- if (BaseOut == "16")
- RBHEXOut->Checked = true;
- if (BaseOut == "8")
- RBOCTOut->Checked = true;
-
- GetPrivateProfileString("Data", "AngularUnit", "2", tempStr,
- 64999, NameOfFile.c_str());
- AngularUnit = tempStr;
- if (AngularUnit == "1")
- RBDEG->Checked = true;
- if (AngularUnit == "2")
- RBRAD->Checked = true;
- if (AngularUnit == "3")
- RBGRA->Checked = true;
- }
- delete[] tempStr;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFParser::BHelpClick(TObject *Sender)
- {
- char* helpstr = "sbParser";
-
- WinHelp(Handle, "..\\help\\csbparse.hlp", HELP_KEY, (unsigned long)helpstr);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFParser::BSpeedTestClick(TObject *Sender)
- {
- FSpeedTest->ShowModal();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TFParser::BPlotTestClick(TObject *Sender)
- {
- FPlotTest->ShowModal();
- }
- //---------------------------------------------------------------------------
-
-